/*
 * @Descripttion: 
 * @Author: voanit
 * @Date: 2022-06-07 17:56:42
 * @LastEditors: voanit
 * @LastEditTime: 2022-06-08 12:24:57
 */
/**
 * 获取文章列表
 * @param channel_id 获取文章列表
 * @param timestamp 时间戳
 * @returns
 */
import { ApiResponse, Article } from '@/types/data'
import { RootThunkAction } from '@/types/store'
import request from '@/utils/request'

export const getArticleList = (
  channel_id: number,
  timestamp: string
): RootThunkAction => {
  return async (dispatch) => {
    const res = await request.get<ApiResponse<{ pre_timestamp: string, results: Article[] }>>('/articles', { params: { channel_id, timestamp } })
    // 答应查看请求结果
    // console.log(res, channel_id, 333)
    dispatch({
      type: 'article/saveChannelArticles',
      payload: {
        channel_id: channel_id,
        timestamp: res.data.data.pre_timestamp,
        articles: res.data.data.results
      }
    })
  }
}


export const getNewArticleList = (
  channel_id: number,
  timestamp: string
): RootThunkAction => {
  return async (dispatch) => {
    const res = await request.get<ApiResponse<{ pre_timestamp: string, results: Article[] }>>('/articles', { params: { channel_id, timestamp } })
    // 答应查看请求结果
    // console.log(res, channel_id, 1333)
    dispatch({
      type: 'article/getNewArticles',
      payload: {
        channel_id: channel_id,
        timestamp: res.data.data.pre_timestamp,
        articles: res.data.data.results
      }
    })
  }
}